#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5,mod=1e9+7;
inline void read(int &x){
	x=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
}
int n,k,a[N],stk[N],top;
long long f[N],ans;
struct Tree{
	long long mx,tag;
}t[N<<2];
inline void pushdown(int p){
	if(t[p].tag){
		t[2*p].tag+=t[p].tag;
		t[2*p].mx+=t[p].tag;
		t[2*p+1].tag+=t[p].tag;
		t[2*p+1].mx+=t[p].tag;
		t[p].tag=0;
	}
}
#define ls 2*p,l,mid,lt,rt
#define rs 2*p+1,mid+1,r,lt,rt
#define mid ((l+r)>>1)
void change(int p,int l,int r,int lt,int rt,int v){
	if(lt<=l&&r<=rt){
		t[p].tag+=v,t[p].mx+=v;
		return;
	}
	pushdown(p);
	if(lt<=mid) change(ls,v);
	if(mid<rt) change(rs,v);
	t[p].mx=min(t[2*p].mx,t[2*p+1].mx);
}
long long query(int p,int l,int r,int lt,int rt){
	if(lt<=l&&r<=rt) return t[p].mx;
	pushdown(p);
	long long ans=1e18;
	if(lt<=mid) ans=min(ans,query(ls));
	if(mid<rt) ans=min(ans,query(rs));
	return ans; 
}
int main(){
	freopen("knight.in","r",stdin);
	freopen("knight.out","w",stdout);
	read(n),read(k);
	for(int i=1;i<=n;++i){
		read(a[i]);
		while(top&&a[stk[top]]<=a[i]){
			change(1,0,n,stk[top-1],stk[top]-1,a[i]-a[stk[top]]);
			--top;
		}
		change(1,0,n,i-1,i-1,f[i-1]+a[i]);
		stk[++top]=i;
		f[i]=query(1,0,n,max(0,i-k),i-1);
	}
	for(int i=n,w=1;i;--i){
		ans=(ans+f[i]%mod*w%mod)%mod;
		w=23ll*w%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

